const requestPost = parmas=> {
    wx.request({
        url: parmas.url,
        data: parmas.data,
        header: parmas.header,
        method: 'POST',
        dataType: 'json',
        responseType: 'text',
        success: function (res) { 
            if (res.statusCode == 200) {
                if (parmas.success) {
                    parmas.success(res)
                }
            }else{
                if (parmas.fail) {
                    parmas.fail(res)
                }
            }
        },
        fail: function (res) {
            if (parmas.fail) {
                parmas.fail(res)
            }
         },
        complete: function (res) {
            if (parmas.complete) {
                parmas.complete(res)
            }
         },
    });
}
const requestGet = parmas => {
    wx.request({
        url: parmas.url,
        data: parmas.data,
        header: parmas.header,
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: function (res) {
            if (res.statusCode == 200) {
                if (parmas.success) {
                    parmas.success(res)
                }
            } else {
                if (parmas.fail) {
                    parmas.fail(res)
                }
            }
        },
        fail: function (res) {
            if (parmas.fail) {
                parmas.fail(res)
            }
        },
        complete: function (res) {
            if (parmas.complete) {
                parmas.complete(res)
            }
        },
    });
}

module.exports = {
    requestPost: requestPost,
    requestGet: requestGet
}